// alert(1);
var str = location.href;
// alert(str);
// 获取当页面的Id
var arr = str.split("=");
// alert(arr[1]);
// alert(arr[0])
$(function(){
	$.ajax({
		type:"post",
		url:" /v1/website/article-detail",
		data:{id:arr[1]},
		dataType:"json",
		
		success:function (data){
			console.log(data);
			if(data.code == 200) {
				// 产品列表
				var list = data.data;
				var rateLsit = list.detail;
// 				alert(rateLsit.title)
// 				alert(rateLsit.publish_time)
// 				alert(rateLsit.head_img)
// 				alert(rateLsit.head_img_alt)
				// 图片
				var banner = list.cover_img;
				var nextID = list.next_id;
				var preID  = list.pre_id;
				// alert(nextID);
				// alert(preID);
				// var bannerPic = '';
				// 产品列表数据
				// alert(rateLsit.title);
				// for(var i=0; i<rateLsit.length;i++){
				var htmlStr = '<div class="newsTitle"><h3>'+ rateLsit.title +'</h3><h6>日期：' +rateLsit.publish_time + '</h6></div>'
				var htmlStr1 ='<div class="newscontent"> '+  rateLsit.content+' </div>'		
				var htmlStr2 = '<div class="newsPic"><img src=" '+ rateLsit.head_img +'" alt=" '+ rateLsit.head_img_alt +' " width="840" height="540"/></div>'		
				
				var next = '';
				var pre = '';
				// 当前连接
				// var url = location.href;
				// var arr =  url.split("=");
				var NnewURL = arr[0] + '=' + nextID;
				var PnewURL = arr[0] + '=' + preID;
				// alert(NnewURL);
				// alert(PnewURL);
				// 设置meta标签
				var descriptionMeta = rateLsit.content;
				var keywordsMeta = rateLsit.keywords;	
					// <div class="newsPic"><img src=""/></div>
					// <div class="newscontent"></div>
				}
				// 翻页按钮
				// nexturl = location.href
				// preurl = 
				if(preID == ''){
					$("#preNews").click(function(){
                       return false;
                     })
					
				}else{
					$('#preNews').click(function () {
						$(window).attr('location',PnewURL);
					} )
					$("#preNews").css("color","blue")
				}
				if(nextID == ''){
					$("#nextNews").click(function(){
					   return false;
					 })
					$("#nextNews").css("color","#ccc")
				}else{
					$('#nextNews').click(function () {
						$(window).attr('location',NnewURL);
					})
					$("#nextNews").css("color","blue")
				}
				
				
				$('.newsTitle').html(htmlStr);
				$('.newscontent').html(htmlStr1);
				$('.newsPic').html(htmlStr2);
				$("meta[name='description']").attr('content', descriptionMeta);
				$("meta[name='keywords']").attr('content', keywordsMeta);
				 // $('.productItem').html(htmlStr);
		         // $('.newscontent').html()
				$('.bannerProduct img').attr('src', banner);
			},
		error: function (XMLHttpRequest) {
			if( XMLHttpRequest.status == 400)
			{
				location.href = "404.html";
			}
			else
			{
				location.href = "505.html";
			}
		}
	    })
  })
  
  
  